package com.yuju.rpt.service.impl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuju.common.core.dao.IBaseDao;
import com.yuju.common.core.service.AbstractBaseService;
import com.yuju.enums.ReturnCodeEnum;
import com.yuju.exception.BusinessException;
import com.yuju.hotel.enums.CustomersEnum;
import com.yuju.order.enums.RentTypeEnum;
import com.yuju.rpt.dao.IBusinessDailyDao;
import com.yuju.rpt.dao.entity.BusinessDaily;
import com.yuju.rpt.enums.BusinessDailyReturnCodeEnum;
import com.yuju.rpt.enums.ReportTypeEnum;
import com.yuju.rpt.model.BusinessDailyModel;
import com.yuju.rpt.model.CheckinCustomTypeDetailModel;
import com.yuju.rpt.model.CheckinCustomTypeModel;
import com.yuju.rpt.model.CheckinRoomTypeModel;
import com.yuju.rpt.service.IBusinessDailyService;
import com.yuju.rpt.service.ICheckinCustomTypeDetailService;
import com.yuju.rpt.service.ICheckinCustomTypeService;
import com.yuju.rpt.service.ICheckinRoomTypeService;
import com.yuju.util.ExcelExp;
import com.yuju.util.Utils;

/**
 * 类名：BusinessDailyServiceImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2018年1月30日 下午5:55:38  <br />
 * @version : 1.1 <br />
 */
@Service
public class BusinessDailyServiceImpl extends AbstractBaseService<BusinessDailyModel, BusinessDaily, String> implements IBusinessDailyService {
	
	@Autowired
	private IBusinessDailyDao businessDailyDao;
	
	@Autowired
	private ICheckinCustomTypeService checkinCustomTypeService;
	
	@Autowired
	private ICheckinCustomTypeDetailService checkinCustomTypeDetailService;
	
	@Autowired
	private ICheckinRoomTypeService checkinRoomTypeService;
	
	@Override
	public IBaseDao<BusinessDailyModel, BusinessDaily, String> getDao() {
		return businessDailyDao;
	}
	@Override
	public int save(BusinessDailyModel businessDailyModel){
		businessDailyModel.setId(Utils.getUUID());
		Date date = new Date();
		businessDailyModel.setGmtCreate(date);
		businessDailyModel.setGmtModified(date);
		return super.save(businessDailyModel);
	}

	/**
	 * 功能:获得报表中的订单账务数据 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2018年1月30日 下午6:16:27<br/>
	 * 
	 * @param map
	 * @return <br/>
	 * @see com.yuju.rpt.service.IBusinessDailyService#getAccountReportStat(java.util.Map)
	 */
	@Override
	public BusinessDailyModel getAccountReportStat(Map<Object, Object> map) {
		return businessDailyDao.getAccountReportStat(map);
	}

	/**
	 * 功能:获得报表中的账务数据 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2018年1月30日 下午6:41:33<br/>
	 * 
	 * @param map
	 * @return <br/>
	 * @see com.yuju.rpt.service.IBusinessDailyService#getUnitAccountReportStat(java.util.Map)
	 */
	@Override
	public List<BusinessDailyModel> getAccountReportMessage(Map<Object, Object> map) {
		return businessDailyDao.getAccountReportMessage(map);
	}

	/**
	 * 功能:生成营业日报 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2018年1月31日 下午5:12:04<br/>
	 * 
	 * @param businessDailyModel
	 * @return <br/>
	 * @throws ParseException 
	 * @see com.yuju.rpt.service.IBusinessDailyService#saveBusinessDailyReport(com.yuju.rpt.dao.model.BusinessDailyModel)
	 */
	@Override
	public int saveBusinessDailyReport(Date businessDate) {
		BusinessDailyModel businessDailyModel = new BusinessDailyModel();
		businessDailyModel.setBusinessDate(businessDate);
		businessDailyModel.setBeginTime(businessDate);
		businessDailyModel.setEndTime(new Date(businessDate.getTime() +(long)24*60*60*1000) );
		HashMap<Object,Object> map = new HashMap<>();
		map.put("gmtCreate",businessDailyModel.getBusinessDate() );
		List<BusinessDailyModel> list = this.getAccountReportMessage(map);
		int i = 0;
		for (BusinessDailyModel model : list) {
			model.setBusinessDate(businessDailyModel.getBusinessDate());
			model.setBeginTime(businessDailyModel.getBeginTime());
			model.setEndTime(businessDailyModel.getEndTime());
			BusinessDailyModel businessDailyModelYes = new BusinessDailyModel();
			businessDailyModelYes.setHotelId(model.getHotelId());
			businessDailyModelYes.setBusinessDate(new Date(model.getBusinessDate().getTime() - (long)24*60*60*1000));
			BusinessDailyModel find = this.find(businessDailyModelYes);
			if(Utils.isNotNull(find)){
				model.setSsPriorBalance(find.getSsCurrentBalance());
			}else{
				model.setSsPriorBalance(new BigDecimal("0"));
			}
			if(Utils.isNotNull(model.getSsQtSum())){
				model.setSsCurrentCheck(model.getSsQtSum().subtract(model.getYsSum()));
			}else{
				model.setSsCurrentCheck(new BigDecimal("0"));
			}
			model.setSsCurrentBalance(model.getSsPriorBalance().add(model.getSsCurrentCheck()));
			model.setType(ReportTypeEnum.REPORTTYPE_DAY.getValue());
			if(this.save(model)<1){
				throw new BusinessException(BusinessDailyReturnCodeEnum.BUSENESSDAILY_SAVE_FAILURE.getCode(),
						BusinessDailyReturnCodeEnum.BUSENESSDAILY_SAVE_FAILURE.getDesc());
			}
			i++;
		}
		return i;
	}
	/**
	 * 功能:导出营业日报 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2018年2月1日 上午11:36:05<br/>
	 * 
	 * @param businessDailyModel
	 * @return
	 * @throws IOException <br/>
	 * @see com.yuju.rpt.service.IBusinessDailyService#expBusinessDailyRpt(com.yuju.rpt.dao.model.BusinessDailyModel)
	 */
	@Override
	public byte[] expBusinessDailyRpt(BusinessDailyModel businessDailyModel) throws IOException {
		
		ExcelExp e = new ExcelExp();
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		e.createRow(0);
		e.setCell(0, "编号");
		e.setCell(1, "项目");
		e.setCell(2, "当日发生");
		e.setCell(3, "当月累计");
		e.setCell(4, "去年同期");
		e.setColumnWidth(0, 5000);
		e.setColumnWidth(1, 7500);
		e.setColumnWidth(2, 5000);
		e.setColumnWidth(3, 5000);
		e.setColumnWidth(4, 5000);
		
		
		
		BusinessDailyModel model = this.find(businessDailyModel);
		if (Utils.isNull(model)) {
			throw new BusinessException(ReturnCodeEnum.NO_DATA.getCode(), ReturnCodeEnum.NO_DATA.getDesc());
		}
		e.createRow(1);
		e.setCell(0, "A=A1+A2");
		e.setCell(1, "一、营业收入");
		e.setCell(2, model.getYsSum().toString());
		e.createRow(2);
		e.setCell(0, "A1=a1+a2");
		e.setCell(1, "房费总收入");
		e.setCell(2, model.getYsFfSum().toString());
		e.createRow(3);
		e.setCell(0, "a1");
		e.setCell(1, "1.日租收入");
		e.setCell(2, model.getYsFfRzSum().toString());
		e.createRow(4);
		e.setCell(1, "夜审全日租");
		e.setCell(2, model.getYsFfRzYs().toString());
		e.createRow(5);
		e.setCell(1, "全日租");
		e.setCell(2, model.getYsFfRzQrz().toString());
		e.createRow(6);
		e.setCell(1, "半日租");
		e.setCell(2, model.getYsFfRzBrz().toString());
		e.createRow(7);
		e.setCell(1, "钟点房费");
		e.setCell(2, model.getYsFfRzZdf().toString());
		e.createRow(8);
		e.setCell(1, "房费折扣");
		e.setCell(2, model.getYsFfRzFfzk().toString());
		e.createRow(9);
		e.setCell(1, "加床费");
		e.setCell(2, model.getYsFfRzJcf().toString());
		e.createRow(10);
		e.setCell(0, "a2");
		e.setCell(1, "2.公寓收入");
		e.setCell(2, model.getYsFfGySum().toString());
		e.createRow(11);
		e.setCell(1, "公寓夜审房费");
		e.setCell(2, model.getYsFfGyYs().toString());
		e.createRow(12);
		e.setCell(1, "日租金");
		e.setCell(2, model.getYsFfGyRzj().toString());
		e.createRow(13);
		e.setCell(1, "房费折扣");
		e.setCell(2, model.getYsFfGyFfzk().toString());
		e.createRow(14);
		e.setCell(0, "A2");
		e.setCell(1, "3.商品消费");
		e.setCell(2, model.getYsXsdSum().toString());
		e.createRow(15);
		e.setCell(1, "房费");
		e.setCell(2, model.getYsXsdFf().toString());
		e.createRow(16);
		e.setCell(1, "大堂吧");
		e.setCell(2, model.getYsXsdQtb().toString());
		e.createRow(17);
		e.setCell(1, "客房吧");
		e.setCell(2, model.getYsXsdKfb().toString());
		e.createRow(18);
		e.setCell(1, "赔偿");
		e.setCell(2, model.getYsXsdKfpc().toString());
		e.createRow(19);
		e.setCell(1, "餐饮");
		e.setCell(2, model.getYsXsdCyb().toString());
		e.createRow(20);
		e.setCell(1, "会议");
		e.setCell(2, model.getYsXsdHy().toString());
		e.createRow(21);
		e.setCell(1, "代收");
		e.setCell(2, model.getYsXsdDs().toString());
		e.createRow(22);
		e.setCell(1, "服务费");
		e.setCell(2, model.getYsXsdFw().toString());
		e.createRow(23);
		e.setCell(1, "其他");
		e.setCell(2, model.getYsXsdQt().toString());
		e.createRow(24);
		e.setCell(0, "B");
		e.setCell(1, "二、前台收银统计");
		e.setCell(2, model.getSsQtSum().toString());
		e.createRow(25);
		e.setCell(1, "现金");
		e.setCell(2, model.getSsQtCashSum().toString());
		e.createRow(26);
		e.setCell(1, "现金");
		e.setCell(2, model.getSsQtCashSum().toString());
		e.createRow(27);
		e.setCell(1, "银行卡转账");
		e.setCell(2, model.getSsQtZzSum().toString());
		e.createRow(28);
		e.setCell(1, "银行卡刷卡");
		e.setCell(2, model.getSsQtSkSum().toString());
		e.createRow(29);
		e.setCell(1, "支付宝");
		e.setCell(2, model.getSsQtZfbSum().toString());
		e.createRow(30);
		e.setCell(1, "支付宝转账");
		e.setCell(2, 0);
		e.createRow(31);
		e.setCell(1, "微信");
		e.setCell(2, model.getSsQtWxSum().toString());
		e.createRow(32);
		e.setCell(1, "微信转账");
		e.setCell(2, 0);
		e.createRow(33);
		e.setCell(1, "挂账");
		e.setCell(2, model.getSsQtGzSum().toString());
		e.createRow(34);
		e.setCell(1, "免单");
		e.setCell(2, model.getSsQtMdSum().toString());
		e.createRow(35);
		e.setCell(1, "其他收款");
		e.setCell(2, model.getSsQtQtSum().toString());
		e.createRow(36);
		e.setCell(0, "C");
		e.setCell(1, "三、前台余额");
		e.setCell(2, model.getSsCurrentBalance().toString());
		e.createRow(37);
		e.setCell(0, "C1=B-A");
		e.setCell(1, "本期发生");
		e.setCell(2, model.getSsCurrentCheck().toString());
		e.createRow(38);
		e.setCell(0, "C2");
		e.setCell(1, "上期余额");
		e.setCell(2, model.getSsPriorBalance().toString());
		e.createRow(39);
		e.setCell(0, "D");
		e.setCell(1, "四、财务");
		e.setCell(2, 0);
		e.createRow(40);
		e.setCell(1, "1.会员储值");
		e.setCell(2, model.getMemberCzSum().toString());
		e.createRow(41);
		e.setCell(1, "会员现金储值");
		e.setCell(2, model.getMemberCzCash().toString());
		e.createRow(42);
		e.setCell(1, "会员刷卡储值");
		e.setCell(2, model.getMemberCzSk().toString());
		e.createRow(43);
		e.setCell(1, "会员充值赠送");
		e.setCell(2, model.getMemberCzZs().toString());
		e.createRow(44);
		e.setCell(1, "2.会员储值消费");
		e.setCell(2, model.getMemberCzXf().toString());
		e.createRow(45);
		e.setCell(1, "3.会员办卡数");
		e.setCell(2, model.getMemberCount().toString());
		e.createRow(46);
		e.setCell(0, "E");
		e.setCell(1, "4.单位中介预收款");
		e.setCell(2, model.getUnitYskSum().toString());
		e.createRow(47);
		e.setCell(0, "F");
		e.setCell(1, "单位预收款");
		e.setCell(2, model.getUnitYskProtocol().toString());
		e.createRow(48);
		e.setCell(1, "中介预收款");
		e.setCell(2, model.getUnitYskAgent().toString());
		e.createRow(49);
		e.setCell(1, "5.转应收");
		e.setCell(2, model.getUnitYsSum().toString());
		e.createRow(50);
		e.setCell(1, "单位挂账");
		e.setCell(2, model.getUnitYsProtocol().toString());
		e.createRow(51);
		e.setCell(1, "中介挂账");
		e.setCell(2, model.getUnitYsAgent().toString());
		e.createRow(52);
		e.setCell(0, "G");
		e.setCell(1, "6.应收收回");
		e.setCell(2, model.getUnitShSum().toString());
		e.createRow(53);
		e.setCell(1, "单位收回");
		e.setCell(2, model.getUnitShProtocol().toString());
		e.createRow(54);
		e.setCell(1, "中介收回");
		e.setCell(2, model.getUnitShAgent().toString());
		e.createRow(55);
		e.setCell(1, "五、客房销售统计");
		e.setCell(2, 0);
		e.createRow(56);
		e.setCell(0, "H");
		e.setCell(1, "1.总房数");
		e.setCell(2, model.getKfRoomSum().toString());
		e.createRow(57);
		e.setCell(0, "H1");
		e.setCell(1, "维修房数");
		e.setCell(2, model.getKfRoomWx().toString());
		e.createRow(58);
		e.setCell(0, "H2=H-H1");
		e.setCell(1, "可售房数");
		e.setCell(2, model.getKfRoomKs().toString());
		e.createRow(59);
		e.setCell(0, "I=I1+I2+I3");
		e.setCell(1, "2.售房数");
		e.setCell(2, model.getKfSaleSum().toString());
		e.createRow(60);
		e.setCell(0, "I1");
		e.setCell(1, "日租");
		e.setCell(2, model.getKfSaleSk().toString());
		e.createRow(61);
		e.setCell(0, "I2");
		e.setCell(1, "时租");
		e.setCell(2, model.getKfSaleSz().toString());
		e.createRow(62);
		e.setCell(0, "I3");
		e.setCell(1, "公寓");
		e.setCell(2, model.getKfSaleGy().toString());
		e.createRow(63);
		e.setCell(0, "J=I/H");
		e.setCell(1, "3.出租率（总房数）");
		e.setCell(2, model.getKfRateZf().toString());
		e.createRow(64);
		e.setCell(0, "K=I/H2");
		e.setCell(1, "4.出租率（可售房数）");
		e.setCell(2, model.getKfRateKs().toString());
		e.createRow(65);
		e.setCell(0, "L");
		e.setCell(1, "5.出租率（过夜）");
		e.setCell(2, model.getKfRateGy().toString());
		e.createRow(66);
		e.setCell(0, "M=A1");
		e.setCell(1, "6.房费收入");
		e.setCell(2, model.getYsFfSum().toString());
		e.createRow(67);
		e.setCell(0, "M1=a1");
		e.setCell(1, "短租房费");
		e.setCell(2, model.getYsFfRzSum().toString());
		e.createRow(68);
		e.setCell(0, "M2=a2");
		e.setCell(1, "公寓房费");
		e.setCell(2, model.getYsFfGySum().toString());
		e.createRow(69);
		e.setCell(0, "N=M/I");
		e.setCell(1, "7.平均房价");
		e.setCell(2, model.getKfAverage().toString());
		e.createRow(70);
		e.setCell(0, "N1=M1/(I1+I2)");
		e.setCell(1, "短租平均房价");
		e.setCell(2, model.getKfAverageRz().toString());
		e.createRow(71);
		e.setCell(0, "N2=M2/I3");
		e.setCell(1, "公寓平均房价");
		e.setCell(2, model.getKfAverageGy().toString());
		e.createRow(72);
		e.setCell(0, "O=A/H");
		e.setCell(1, "8.RevPAR");
		e.setCell(2, model.getKfRevpar().toString());
		e.createRow(73);
		e.setCell(0, "P=P1+P2");
		e.setCell(1, "六、佣金");
		e.setCell(2, model.getYjSum().toString());
		e.createRow(74);
		e.setCell(0, "P1");
		e.setCell(1, "OTA佣金");
		e.setCell(2, model.getYjOta().toString());
		e.createRow(75);
		e.setCell(0, "P2");
		e.setCell(1, "中介佣金");
		e.setCell(2, model.getYjAgent().toString());
		e.getWorkbook().write(os);
		os.flush();
		return os.toByteArray();
	}
	/**
	 * 功能:导出经理日报<br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2018年2月8日 上午10:13:45<br/>
	 * 
	 * @param businessDailyModel
	 * @return
	 * @throws IOException <br/>
	 * @see com.yuju.rpt.service.IBusinessDailyService#expManagerDailyRpt(com.yuju.rpt.model.BusinessDailyModel)
	 */
	@Override
	public byte[] expManagerDailyRpt(BusinessDailyModel businessDailyModel) throws IOException {
		ExcelExp e = new ExcelExp();
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		BusinessDailyModel model = this.find(businessDailyModel);
		if (Utils.isNull(model)) {
			throw new BusinessException(ReturnCodeEnum.NO_DATA.getCode(), ReturnCodeEnum.NO_DATA.getDesc());
		}
		
		e.setColumnWidth(0, 5000);
		e.setColumnWidth(1, 5000);
		e.setColumnWidth(2, 5000);
		e.setColumnWidth(3, 5000);
		e.setColumnWidth(4, 5000);
		e.setColumnWidth(5, 5000);
		e.setColumnWidth(6, 5000);
		e.setColumnWidth(7, 5000);
		
		e.createRow(0);
		e.setCell(0, "营业收入");
		e.setCell(1, model.getYsSum().toString());
		e.createRow(1);
		e.setCell(0, "总房费收入");
		e.setCell(1, model.getYsFfSum().toString());
		e.createRow(2);
		e.setCell(0, "日租房收入");
		e.setCell(1, model.getYsFfRzSum().toString());
		e.setCell(2, "夜审全日租");
		e.setCell(3, model.getYsFfRzYs().toString());
		e.setCell(4, "全日租");
		e.setCell(5, model.getYsFfRzQrz().toString());
		e.setCell(6, "半日租");
		e.setCell(7, model.getYsFfRzBrz().toString());
		
		e.createRow(3);
		e.setCell(2, "钟点房费");
		e.setCell(3, model.getYsFfRzZdf().toString());
		e.setCell(4, "房费折扣");
		e.setCell(5, model.getYsFfRzFfzk().toString());
		e.setCell(6, "加床费");
		e.setCell(7, model.getYsFfRzJcf().toString());
		
		e.createRow(4);
		e.setCell(0, "公寓房收入");
		e.setCell(1, model.getYsFfGySum().toString());
		e.setCell(2, "公寓日租金");
		e.setCell(3, model.getYsFfGyYs().toString());
		e.setCell(4, "日租金");
		e.setCell(5, model.getYsFfGyRzj().toString());
		e.setCell(6, "房费折扣");
		e.setCell(7, model.getYsFfGyFfzk().toString());
		e.createRow(5);
		e.setCell(0, "商品消费");
		e.setCell(1, model.getYsXsdSum().toString());
		e.setCell(2, "客房吧");
		e.setCell(3, model.getYsXsdKfb().toString());
		e.setCell(4, "大堂吧");
		e.setCell(5, model.getYsXsdQtb().toString());
		e.setCell(6, "赔偿");
		e.setCell(7, model.getYsXsdKfpc().toString());
		e.createRow(6);
		e.setCell(0, "餐饮");
		e.setCell(1, model.getYsXsdCyb().toString());
		e.setCell(2, "服务费");
		e.setCell(3, model.getYsXsdFw().toString());
		e.setCell(4, "代收");
		e.setCell(5, model.getYsXsdDs().toString());
		e.setCell(6, "其他");
		e.setCell(7, model.getYsXsdQt().toString());
		e.createRow(7);
		e.setCell(0, "前台收银分类统计");
		e.createRow(8);
		e.setCell(0, "前台收款");
		e.setCell(1, model.getSsQtSum().toString());
		e.setCell(2, "现金");
		e.setCell(3, model.getSsQtCashSum().toString());
		e.setCell(4, "转账");
		e.setCell(5, model.getSsQtZzSum().toString());
		e.setCell(6, "刷卡");
		e.setCell(7, model.getSsQtSkSum().toString());
		e.createRow(9);
		e.setCell(0, "支付宝");
		e.setCell(1, model.getSsQtZfbSum().toString());
		e.setCell(2, "微信");
		e.setCell(3, model.getSsQtWxSum().toString());
		e.setCell(4, "会员卡");
		e.setCell(5, model.getSsQtMemberSum().toString());
		e.setCell(6, "挂账");
		e.setCell(7, model.getSsQtGzSum().toString());
		e.createRow(10);
		e.setCell(0, "免单");
		e.setCell(1, model.getSsQtMdSum().toString());
		e.setCell(2, "其他收款");
		e.setCell(3, model.getSsQtQtSum().toString());
		e.setCell(4, "预授权");
		e.setCell(5, model.getSsQtYsqSum().toString());
		e.createRow(11);
		e.setCell(0, "宾客账款");
		e.setCell(2, "期初余额");
		e.setCell(3, model.getSsPriorBalance().toString());
		e.setCell(4, "本期发生");
		e.setCell(5, model.getSsCurrentCheck().toString());
		e.setCell(6, "期末余额");
		e.setCell(7, model.getSsCurrentBalance().toString());
		e.createRow(12);
		e.setCell(0, "业绩分析");
		e.setCell(2, "总房数");
		e.setCell(3, model.getKfRoomSum().toString());
		e.setCell(4, "可用房");
		e.setCell(5, model.getKfRoomKs().toString());
		e.setCell(6, "维修房");
		e.setCell(7, model.getKfRoomWx().toString());
		e.createRow(13);
		e.setCell(0, "总售房数");
		e.setCell(1, model.getKfSaleSum().toString());
		e.setCell(2, "散客售房数");
		e.setCell(3, model.getKfSaleSk().toString());
		e.setCell(4, "时租售房数");
		e.setCell(5, model.getKfSaleSz().toString());
		e.setCell(6, "公寓售房数");
		e.setCell(7, model.getKfSaleGy().toString());
		e.createRow(14);
		e.setCell(0, "出租率(日租)");
		e.setCell(1, model.getKfSaleSk().add(model.getKfSaleSz())
				.divide(new BigDecimal(model.getKfRoomSum()), 4, BigDecimal.ROUND_HALF_UP).toString());
		e.setCell(2, "出租率(公寓)");
		e.setCell(3,  new BigDecimal(model.getKfSaleGy().toString())
				.divide(new BigDecimal(model.getKfRoomSum()), 4, BigDecimal.ROUND_HALF_UP).toString());
		e.setCell(4, "平均房价(日租)");
		e.setCell(5, model.getKfAverageRz().toString());
		e.setCell(6, "平均房价(公寓)");
		e.setCell(7, model.getKfAverageGy().toString());
		e.createRow(15);
		e.setCell(6, "RevPAR");
		e.setCell(7, model.getKfRevpar().toString());
		
		e.createRow(16);
		e.setCell(0, "财务记账");
		e.setCell(2, "会员新增");
		e.setCell(3, model.getMemberCount().toString());
		e.setCell(4, "会员充值");
		e.setCell(5, model.getMemberCzSum().toString());
		e.setCell(6, "单位中介预收");
		e.setCell(7, model.getUnitYskSum().toString());
		
		e.createRow(17);
		e.setCell(0, "转应收");
		e.setCell(1, model.getUnitYsSum().toString());
		e.setCell(2, "单位挂账");
		e.setCell(3, model.getUnitYsProtocol().toString());
		e.setCell(4, "中介挂账");
		e.setCell(5, model.getUnitYsAgent().toString());
		e.setCell(6, "应收收回");
		e.setCell(7, model.getUnitShSum().toString());
		
		CheckinCustomTypeModel checkinCustomTypeModel = new CheckinCustomTypeModel();
		checkinCustomTypeModel.setGroupId(businessDailyModel.getGroupId());
		checkinCustomTypeModel.setHotelId(businessDailyModel.getHotelId());
		checkinCustomTypeModel.setBusinessDate(businessDailyModel.getBusinessDate());
		checkinCustomTypeModel.setType(businessDailyModel.getType());
		Map<String, Object> map = checkinCustomTypeService.getRpt(checkinCustomTypeModel);
		CheckinCustomTypeModel modelCustomType = (CheckinCustomTypeModel) map.get("model");
		List<CheckinCustomTypeDetailModel> list = (List<CheckinCustomTypeDetailModel>) map.get("list");
		CheckinCustomTypeDetailModel sum = checkinCustomTypeDetailService.getSum(checkinCustomTypeModel);
		
		e.createRow(18);
		e.setCell(0, "客源售房统计");
		e.setCell(5, "总房数");
		e.setCell(6, modelCustomType.getKfRoomSum());
		e.createRow(19);
		e.setCell(0, "客源类型");
		e.setCell(2, "间夜数");
		e.setCell(3, "出租率");
		e.setCell(4, "占比");
		e.setCell(5, "总收入");
		e.setCell(6, "平均房价");
		e.createRow(20);
		e.setCell(0, "日租");
		e.setCell(1, "散客");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.SHORT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_TYPE_SK.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(21);
		e.setCell(0, "日租");
		e.setCell(1, "会员");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.SHORT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_HY.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(22);
		e.setCell(0, "日租");
		e.setCell(1, "单位");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.SHORT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_XYDW.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(23);
		e.setCell(0, "日租");
		e.setCell(1, "中介");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.SHORT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_OTA.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(24);
		e.setCell(0, "日租");
		e.setCell(1, "业主");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.SHORT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_ZJ.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(25);
		e.setCell(0, "日租");
		e.setCell(1, "员工");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.SHORT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_YZ.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(26);
		e.setCell(0, "长租");
		e.setCell(1, "散客");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_TYPE_SK.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(27);
		e.setCell(0, "长租");
		e.setCell(1, "会员");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_HY.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(28);
		e.setCell(0, "长租");
		e.setCell(1, "单位");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_XYDW.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(29);
		e.setCell(0, "长租");
		e.setCell(1, "中介");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_OTA.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(30);
		e.setCell(0, "长租");
		e.setCell(1, "业主");
		e.setCell(2, 0);
		e.setCell(3, 0);
		e.setCell(4, 0);
		e.setCell(5, 0);
		e.setCell(6, 0);
		for (CheckinCustomTypeDetailModel checkinCustomTypeDetailModel : list) {
			if(checkinCustomTypeDetailModel.getRentType() == RentTypeEnum.APRTMENT.getValue()){
				if(checkinCustomTypeDetailModel.getCustomType() == CustomersEnum.CUSTOMERS_ZJ.getValue()){
					e.setCell(2, checkinCustomTypeDetailModel.getKfSaleSum().toString());
					e.setCell(3, checkinCustomTypeDetailModel.getKfRateZf().toString());
					e.setCell(4, checkinCustomTypeDetailModel.getRate().toString());
					e.setCell(5, checkinCustomTypeDetailModel.getYsFfSum().toString());
					e.setCell(6, checkinCustomTypeDetailModel.getKfAverage().toString());
				}
			}
		}
		e.createRow(31);
		e.setCell(0, "合计");
		e.setCell(2, sum.getKfSaleSum().toString());
		e.setCell(3, sum.getKfRateZf().toString());
		e.setCell(4, sum.getRate().toString());
		e.setCell(5, sum.getYsFfSum().toString());
		e.setCell(6, sum.getKfAverage().toString());
		
		e.createRow(32);
		e.setCell(0, "房型售房统计");
		e.createRow(33);
		e.setCell(0, "房型");
		e.setCell(1, "总房数");
		e.setCell(2, "入住数");
		e.setCell(3, "出租率");
		e.setCell(4, "总收入");
		e.setCell(5, "平均房价");
		
		CheckinRoomTypeModel checkinRoomTypeModelFind = new CheckinRoomTypeModel();
		checkinRoomTypeModelFind.setBusinessDate(businessDailyModel.getBusinessDate());
		checkinRoomTypeModelFind.setHotelId(businessDailyModel.getHotelId());
		checkinRoomTypeModelFind.setGroupId(businessDailyModel.getGroupId());
		checkinRoomTypeModelFind.setType(businessDailyModel.getType());
		List<CheckinRoomTypeModel> listRoomType = checkinRoomTypeService.list(checkinRoomTypeModelFind);
		for (int i = 0; i < listRoomType.size(); i++) {
			e.createRow(i+34);
			e.setCell(0, listRoomType.get(i).getRoomTypeName());
			e.setCell(1, listRoomType.get(i).getKfRoomSum());
			e.setCell(2, listRoomType.get(i).getKfSaleSum().toString());
			e.setCell(3, listRoomType.get(i).getKfRateZf().toString());
			e.setCell(4, listRoomType.get(i).getYsFfSum().toString());
			e.setCell(5, listRoomType.get(i).getKfAverage().toString());
		}
		CheckinRoomTypeModel checkinStatByRoomTypeSum = checkinRoomTypeService.getCheckinStatByRoomTypeSum(checkinRoomTypeModelFind);
		
		e.createRow(listRoomType.size()+34);
		e.setCell(0, checkinStatByRoomTypeSum.getRoomTypeName());
		e.setCell(1, checkinStatByRoomTypeSum.getKfRoomSum());
		e.setCell(2, checkinStatByRoomTypeSum.getKfSaleSum().toString());
		e.setCell(3, checkinStatByRoomTypeSum.getKfRateZf().toString());
		e.setCell(4, checkinStatByRoomTypeSum.getYsFfSum().toString());
		e.setCell(5, checkinStatByRoomTypeSum.getKfAverage().toString());
		
		e.createRow(listRoomType.size()+35);
		e.setCell(0, "明日预订详情");
		e.createRow(listRoomType.size()+36);
		e.setCell(0, "明日预抵");
		if(Utils.isNotNull(businessDailyModel.getReserveNextIn())){
			e.setCell(1, businessDailyModel.getReserveNextIn());
		}else{
			e.setCell(1, 0);
		}
		e.setCell(2, "明日预离");
		if(Utils.isNotNull( businessDailyModel.getReserveNextOut())){
			e.setCell(3, businessDailyModel.getReserveNextOut());
		}else{
			e.setCell(3, 0);
		}
		e.getWorkbook().write(os);
		os.flush();
		return os.toByteArray();
	}
}
